<template>
  <el-table
    :data="tableData"
    style="width: 100%"
    :row-class-name="tableRowClassName"
  >
    <el-table-column label="日期" width="300" align="center">
      <template slot-scope="scope">
        <i class="el-icon-time"></i>
        <span style="margin-left: 10px">{{ scope.row.date }}</span>
      </template>
    </el-table-column>
    <el-table-column label="姓名" width="300" align="center">
      <template slot-scope="scope">
        <el-popover trigger="hover" placement="top">
          <p>姓名: {{ scope.row.name }}</p>
          <p>打卡情况: {{ scope.row.address }}</p>
          <div slot="reference" class="name-wrapper">
            <el-tag size="medium">{{ scope.row.name }}</el-tag>
          </div>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="操作" align="center">
      <template slot-scope="scope">
        <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
          >编辑</el-button
        >
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)"
          >删除</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        {
          date: "2016-05-02",
          name: "刻晴",
          address: "已打卡",
        },
        {
          date: "2016-05-04",
          name: "莫娜",
          address: "未打卡",
        },
        {
          date: "2016-05-01",
          name: "凝光",
          address: "已打卡",
        },
        {
          date: "2016-05-03",
          name: "可莉",
          address: "已打卡",
        },
        {
          date: "2016-05-02",
          name: "刻晴",
          address: "已打卡",
        },
        {
          date: "2016-05-04",
          name: "莫娜",
          address: "未打卡",
        },
        {
          date: "2016-05-01",
          name: "凝光",
          address: "已打卡",
        },
        {
          date: "2016-05-03",
          name: "可莉",
          address: "已打卡",
        },
        {
          date: "2016-05-02",
          name: "刻晴",
          address: "已打卡",
        },
        {
          date: "2016-05-04",
          name: "莫娜",
          address: "未打卡",
        },
        {
          date: "2016-05-01",
          name: "凝光",
          address: "已打卡",
        },
        {
          date: "2016-05-03",
          name: "可莉",
          address: "已打卡",
        },
      ],
    };
  },
  methods: {
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      this.tableData.splice(index, 1);
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.address === "未打卡") {
        console.log(row);
        return "warning-row";
      } else if (row.address === "已打卡") {
        return "success-row";
      }
      return "";
    },
  },
};
</script>

<style>
.el-table .warning-row {
  background: rgb(255, 193, 193);
}

.el-table .success-row {
  background: #cfffb6;
}
</style>
